package aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import domain.User;
import utils.BaseUtil;

@Aspect
@Component
public class MDAspect {
	//测试
	public MDAspect() {
		System.out.println("this is mdaspect");
	}
										//执行		*返回值			方法名	参数列表   
	private final String logPointcut = "execution(* service.StuManager.log*(..))";
	private final String regPointcut = "execution(* service.StuManager.reg*(..))";
	
	@Around(logPointcut)
	public Object loginMdProcess(ProceedingJoinPoint jp){
		Object o = null;
		String psd = (String) jp.getArgs()[1];
		try {
			o=jp.proceed(new Object[]{jp.getArgs()[0],BaseUtil.JohnMd(psd, "md5")});
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return o;
	}
	@Around(regPointcut)
	public Object around(ProceedingJoinPoint point){
		Object o = null;
		User s = (User) point.getArgs()[0];
		System.out.println("this is before");
		s.setPsd(BaseUtil.JohnMd(s.getPsd(), "md5"));
		try {
			o = point.proceed();
			System.out.println("this is after");
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return o;
	}
}
